import { Tag } from 'antd';
import React, { Component } from 'react';

class UseStateRightChild extends Component {

    state = {
        childCount: 0
    }

    componentDidUpdate({ count }) {
        if (count !== this.props.count) {
            this.setState({ childCount: count })
        }
    }

    // static getDerivedStateFromProps(props, state) {
    //     if (props.count !== state.count) {
    //         return {
    //             childCount: props.count
    //         }
    //     }
    //     return null;
    // }

    render() {

        console.info('componentDidUpdate几次渲染');

        // console.info('static getDerivedStateFromProps几次渲染');
        return (
            <div>
                <Tag color='cyan'>更新后count的值：{this.state.childCount}</Tag>
            </div>
        )
    }
}

export default UseStateRightChild;